# subprocess 模块
import subprocess
# 执行系统命令
subprocess.run('ls')                # 仅执行纯命令
subprocess.run(['ls', '/opt'])      # 列表方式，执行带参数的命令
subprocess.run('echo $HOME', shell=True)    # 执行带变量的命令

def ping(host):
    # 执行系统命令 
    result = subprocess.run(f'ping -c 3 {host} &> /dev/null', shell=True)
    if result.returncode == 0:
        print(f'{host}:up')
    else:
        print(f'{host}:down')

if __name__ == '__main__':
    # ping('192.168.88.130')
    # ping('127.0.0.1')
    hosts = ['www.js.com', '192.168.1.1', '127.0.0.1']
    for item in hosts:
        ping(item)
        